﻿using LogManager.Core.Models;
using LogManager.Utils.Unity;
using LogManager.Utils.Xml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Xml.Linq;
using LogManager.Core.Factories;

namespace LogManager.Core.Helpers
{
    public static class XmlResolverExtensions
    {
        public static void SetChild<TBaseElement, TChild>(this XmlResolver<TBaseElement> xmlResolver, Expression<Func<TBaseElement, TChild>> propertyExp, TChild value)
            where TChild : IXmlElement
        {
            xmlResolver.SetChild(propertyExp, value.BaseNode);
        }

        public static void SetChildren<TBaseElement, TChild>(
            this XmlResolver<TBaseElement> xmlResolver,
            Expression<Func<TBaseElement, IEnumerable<TChild>>> propertyExp,
            IEnumerable<IXmlElement> values)
        {
            xmlResolver.SetChildren(propertyExp, values.Select(p => p.BaseNode));
        }
    }
}
